use "/Users/patricktucker/Documents/gpt_jop_replication.dta"

sort responseid
gen dummy=_n
*******Key for variables
****control_rating: Legislator Thermometer for Replication (Table 1, column 1) from 0 to 100
****grant_draw: Size of grant announced in vignette (in millions)
****pid_match: Trichotomous Variable indicating a partisan match with subject and legislator in vignette, -1=Opposite Party, 0=Independent subject, 1=Match
****pid_three: Respondent Party 0=Independent; 1=Democrat; 2=Republican
****college_grad: 1=College Graduate; 0=No College Degree
****ideo7=Respondent ideology. 1=Extremely Liberal; 4=Moderate; 7=Extremely Conservative
****treatment_rating1_1:Legislator Thermometer for Extension, Round 1 (Appendix Table 1, column 1) from 0 to 100
****context1_num: First round context of grant variable that provides the size of the grant relative to the average grant continuous scale from .5 to 3
****context1_3: First round context of grant variable that provides the size of the grant relative to the average grant; 0=same as average; 1=greater than average; 2=less than average
****wave=round in which rating was provided
****experiment_rating: Legislator Thermometer for Extension, from 0 to 100
****experiment_context:Context of grant variable that provides the size of the grant relative to the average grant continuous scale from .5 to 3
****less_context: 1=grant less than average; 0=otherwise
****equal_context: 1=grant equal to average; 0=otherwise
****more_context: 1=grant greater than average; 0=otherwise
***balance checks




****Table 1, column 1
reg control_rating c.grant_draw c.pid_match
*outreg2 using "~\Table1.doc", word replace
generate in_t1_c1 = e(sample)
******Summary statistics for in sample cases for Table 1, column 1
sum control_rating grant_draw pid_match if in_t1_c1==1


*****Recode Context Treatments to numeric
gen context1_num=.
replace context1_num=1 if context_one=="the same amount as"
replace context1_num=.5 if context_one=="50% less than"
replace context1_num=.75 if context_one=="25% less than"
replace context1_num=.95 if context_one=="5% less than"
replace context1_num=1.05 if context_one=="5% more than"
replace context1_num=1.25 if context_one=="25% more than"
replace context1_num=1.5 if context_one=="50% more than"
replace context1_num=2 if context_one=="100% more than"
replace context1_num=3 if context_one=="200% more than"

gen context2_num=.
replace context2_num=1 if context_two=="the same amount as"
replace context2_num=.5 if context_two=="50% less than"
replace context2_num=.75 if context_two=="25% less than"
replace context2_num=.95 if context_two=="5% less than"
replace context2_num=1.05 if context_two=="5% more than"
replace context2_num=1.25 if context_two=="25% more than"
replace context2_num=1.5 if context_two=="50% more than"
replace context2_num=2 if context_two=="100% more than"
replace context2_num=3 if context_two=="200% more than"

gen context3_num=.
replace context3_num=1 if context_three=="the same amount as"
replace context3_num=.5 if context_three=="50% less than"
replace context3_num=.75 if context_three=="25% less than"
replace context3_num=.95 if context_three=="5% less than"
replace context3_num=1.05 if context_three=="5% more than"
replace context3_num=1.25 if context_three=="25% more than"
replace context3_num=1.5 if context_three=="50% more than"
replace context3_num=2 if context_three=="100% more than"
replace context3_num=3 if context_three=="200% more than"

*****Demographics
gen pid_three=.
replace pid_three=1 if pid1=="Democrat"
replace pid_three=2 if pid1=="Republican"
replace pid_three=0 if pid1=="Independent" | pid1=="No preference" | pid1=="Other"

gen college_grad=.
replace college_grad=1 if education=="4 year college degree" | education=="Post-graduate degree"
replace college_grad=0 if education=="Some college" | education=="2 year college degree" | education=="High school degree or equivalent" | education=="Less than high school"

gen ideo7=.
replace ideo7=1 if ideology=="Extremely liberal"
replace ideo7=2 if ideology=="Liberal"
replace ideo7=3 if ideology=="Slightly liberal"
replace ideo7=7 if ideology=="Extremely conservative"
replace ideo7=6 if ideology=="Conservative"
replace ideo7=5 if ideology=="Slightly conservative"
replace ideo7=4 if ideology=="Moderate or middle of the road"

***Categorical Context
gen context1_3=.

replace context1_3=1 if context1_num>1
replace context1_3=2 if context1_num<1
replace context1_3=0 if context1_num==1

gen context2_3=.

replace context2_3=1 if context2_num>1
replace context2_3=2 if context2_num<1
replace context2_3=0 if context2_num==1

gen context3_3=.

replace context3_3=1 if context3_num>1
replace context3_3=2 if context3_num<1
replace context3_3=0 if context3_num==1


***Just first draw
***Appendix Table A5
***Column 1
reg treatment_rating1_1 grant_draw  context1_num pid_match
**Column 2
reg treatment_rating1_1 grant_draw i.context1_3 pid_match
generate in_ta1_c = e(sample)
******Summary statistics for in sample cases for Appendix Table
sum treatment_rating1_1 context1_num pid_match context1_3 if in_ta1_c==1

reg treatment_rating1_1  i.context1_3  if context1_3!=0



**Column 2
reg treatment_rating2_1  i.context2_3 if context2_3!=0
reg treatment_rating3_1  i.context3_3 if context3_3!=0

gen pid7=.
replace pid7=1 if pid1=="Democrat" & pid_dem=="Strong Democrat"
replace pid7=2 if pid1=="Democrat" & pid_dem=="Not a very strong Democrat"
replace pid7=3 if pid1=="Independent" & pid_lean=="Democratic"
replace pid7=3 if pid1=="No preference" & pid_lean=="Democratic"
replace pid7=3 if pid1=="Other" & pid_lean=="Democratic"
replace pid7=4 if pid1=="Other" & pid_lean=="No preference"
replace pid7=4 if pid1=="No preference" & pid_lean=="No preference"
replace pid7=4 if pid1=="Independent" & pid_lean=="No preference"
replace pid7=5 if pid1=="Independent" & pid_lean=="Republican"
replace pid7=5 if pid1=="No preference" & pid_lean=="Republican"
replace pid7=5 if pid1=="Other" & pid_lean=="Republican"
replace pid7=6 if pid1=="Republican" & pid_rep=="Not a very strong Republican"
replace pid7=7 if pid1=="Republican" & pid_rep=="Strong Republican"

gen white=0
replace white=1 if race=="White"
replace white=. if race==""

gen inc_num=.
replace inc_num=1 if income=="$30,000 or less"
replace inc_num=2 if income=="More than $30,000 and less than $60,000"
replace inc_num=3 if income=="More than $60,000 and less than $90,000"
replace inc_num=4 if income=="More than $90,000 and less than $120,000"
replace inc_num=5 if income=="More than $120,000 and less than $150,000"
replace inc_num=6 if income=="More than $150,000"

gen female=.
replace female=1 if sex=="Female"
replace female=0 if sex=="Male"


***Table A16

foreach x of varlist ideo7 college_grad pid7 white inc_num female{

corr grant_draw  `x'
}

foreach x of varlist ideo7 college_grad pid7 white inc_num female{

corr context1_num  `x'
}


foreach x of varlist ideo7 college_grad pid7 white inc_num female{

mean   `x' if grant_draw<4.85
}

foreach x of varlist ideo7 college_grad pid7 white inc_num female{

mean   `x' if grant_draw>4.85
}

foreach x of varlist ideo7 college_grad pid7 white inc_num female{

mean   `x' if context1_num<1.05
}

foreach x of varlist ideo7 college_grad pid7 white inc_num female{

mean   `x' if context1_num>1.05
}


gen pid_leg=.
replace pid_leg=1 if pid=="D"
replace pid_leg=2 if pid=="R"
****Table A10 Column 1
reg control_rating c.grant_draw i.pid_three##i.pid_leg

gen dem_dem=.
replace dem_dem=0 if pid_three==0
replace dem_dem=0 if pid_three==2
replace dem_dem=1 if pid_three==1 & pid_leg==1
replace dem_dem=0 if pid_three==1 & pid_leg==2

gen dem_rep=.
replace dem_rep=0 if pid_three==0
replace dem_rep=0 if pid_three==2
replace dem_rep=1 if pid_three==1 & pid_leg==2
replace dem_rep=0 if pid_three==1 & pid_leg==1

gen rep_rep=.
replace rep_rep=0 if pid_three==0
replace rep_rep=0 if pid_three==1
replace rep_rep=1 if pid_three==2 & pid_leg==2
replace rep_rep=0 if pid_three==2 & pid_leg==1

gen rep_dem=.
replace rep_dem=0 if pid_three==0
replace rep_dem=0 if pid_three==1
replace rep_dem=1 if pid_three==2 & pid_leg==1
replace rep_dem=0 if pid_three==2 & pid_leg==2

gen pair=.
replace pair=0 if pid_three==0
replace pair=1 if pid_three==1 & pid=="D"
replace pair=2 if pid_three==1 & pid=="R"
replace pair=3 if pid_three==2 & pid=="R"
replace pair=4 if pid_three==2 & pid=="D"

**Table A11 Column 1
reg control_rating c.grant_draw i.pid_three i.pair

**Table A12 Column 1
reg control_rating c.grant_draw##i.pair


**Expand to stack responses
expand 3

sort responseid
***Create round variable
egen wave=fill(1 2 3 1 2 3)

***Create rating by round
gen experiment_rating=.

replace experiment_rating= treatment_rating1_1 if wave==1
replace experiment_rating= treatment_rating2_1 if wave==2
replace experiment_rating= treatment_rating3_1 if wave==3

**Create context by round
gen experiment_context=.

replace experiment_context= context1_num if wave==1
replace experiment_context= context2_num if wave==2
replace experiment_context= context3_num if wave==3

**Categorical context by round
gen less_context=.
replace less_context=1 if experiment_context<1
replace less_context=0 if experiment_context>=1

gen equal_context=.
replace equal_context=1 if experiment_context==1
replace equal_context=0 if experiment_context!=1

gen more_context=.
replace more_context=1 if experiment_context>1
replace more_context=0 if experiment_context<=1

gen context_cat=.
replace context_cat=0 if equal_context==1
replace context_cat=1 if less_context==1
replace context_cat=2 if more_context==1


***Table 1 Column 2
reg experiment_rating grant_draw experiment_context pid_match i.wave, cl(responseid)

***Table A10 Column 2
reg experiment_rating grant_draw experiment_context i.pid_three##i.pid_leg i.wave, cl(responseid)

**Table A11 Column 2
reg experiment_rating grant_draw experiment_context i.pid_three i.pair i.wave, cl(responseid)

**Table A12 Column 2
reg experiment_rating grant_draw experiment_context c.grant_draw##i.pair i.wave, cl(responseid)

**Table A13 Column 2
reg experiment_rating grant_draw c.experiment_context##i.pair i.wave, cl(responseid)


**Table 1 Column 3
reg experiment_rating grant_draw i.less_context i.more_context pid_match i.wave, cl(responseid)
generate in_ta1_c2_c3 = e(sample)
***Table A10 Column 3
reg experiment_rating grant_draw i.less_context i.more_context i.pid_three##i.pid_leg i.wave i.wave, cl(responseid)
**Table A11 Column 3
reg experiment_rating grant_draw i.less_context i.more_context i.pid_three i.pair i.wave, cl(responseid)
**Table A12 Column 3
reg experiment_rating grant_draw i.less_context i.more_context c.grant_draw##i.pair i.wave, cl(responseid)
***Table A13, Column 1
reg experiment_rating grant_draw i.less_context##i.pair i.more_context##i.pair i.wave, cl(responseid)

***Table A17 Column1
reg experiment_rating grant_draw c.experiment_context pid_match i.wave if less_context==1, cl(responseid) 
***Table A17 Column 2
reg experiment_rating grant_draw c.experiment_context pid_match i.wave if more_context==1, cl(responseid) 
***Table A17 Column 3
reg experiment_rating grant_draw i.less_context##c.experiment_context pid_match i.wave if more_context==1 | less_context==1, cl(responseid)
outreg2 using "C:\Users\ptucker\Documents\Slope_diff.doc", word append


******Summary statistics for in sample cases for Table 1, column 2&3
sum experiment_rating grant_draw pid_match  experiment_context less_context more_context pid_match wave if in_ta1_c2_c3==1


***Table A15, Column 1
reg experiment_rating grant_draw c.experiment_context##i.pid_three pid_match i.wave, cl(responseid)
***Table A15 Column 2
reg experiment_rating grant_draw c.experiment_context##i.college_grad pid_match i.wave, cl(responseid)
generate in_ta2_c1_c2 = e(sample)
******Summary statistics for in sample cases for Table 2, column 1&2
sum experiment_rating grant_draw pid_match experiment_context pid_three college_grad pid_match wave if in_ta2_c1_c2==1
***Table a15, column 3
reg experiment_rating c.grant_draw c.experiment_context##c.ideo7 pid_match i.wave, cl(responseid)
generate in_ta2_c1_c3 = e(sample)
******Summary statistics for in sample cases for Table 2, column 3
sum experiment_rating grant_draw pid_match experiment_context ideo7 pid_match wave if in_ta2_c1_c3==1



***fixed effect model

 xtset dummy wave
**Table A14 Column 1
xtreg experiment_rating grant_draw experiment_context i.wave, fe
**Table A14 Column 2
xtreg experiment_rating grant_draw i.less_context i.more_context i.wave, fe
